package com.myidis.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.myidis.entity.RightRole;
import com.myidis.request.PermissionReq;
import com.myidis.response.PermissionRes;
import com.myidis.servlet.RightRolePermissionServlet;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;;

@Controller
@RequestMapping("/roleRight")
@Api(tags = "角色的权限管理接口")
public class RightRolePermissionController {
	@Autowired
	private RightRolePermissionServlet rightRolePermissionServlet;
	
	@ResponseBody
	@ApiOperation("获取一个角色的权限")
	@RequestMapping(value="/role",method=RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
	public List<PermissionRes> list(@RequestBody RightRole rightRole) {
		return rightRolePermissionServlet.getByRole(rightRole.getId());
	}

	@ResponseBody
	@ApiOperation("给一个角色进行授权")
	@RequestMapping(value="/right",method=RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
	public int right(@RequestBody RightRole rightRole, @RequestBody List<PermissionReq> req) {
		return rightRolePermissionServlet.right(rightRole.getId(), req);
	}
}
